package com.ihomey.linkuphome.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ihomey.linkuphome.R;
import com.ihomey.linkuphome.entities.Category;

import java.util.List;

/**
 * Created by Administrator on 2016/12/28.
 */

public class UnAddedCategoryAdapter extends RecyclerView.Adapter<UnAddedCategoryAdapter.ViewHolder> {

    public OnUnAddedCategoryItemClickListener mItemClickListener;

    public void setOnUnAddedCategoryItemClickListener(OnUnAddedCategoryItemClickListener listener) {
        mItemClickListener = listener;
    }

    public interface OnUnAddedCategoryItemClickListener {
        public void onItemClick(int pos);
    }

    private Context mContext;
    private List<Category> lamps;

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView titleText;

        public ViewHolder(View view) {
            super(view);
            titleText = (TextView) view.findViewById(R.id.tv_lamp_categoryName);
        }

    }

    public UnAddedCategoryAdapter(Context context, List<Category> lamps) {
        super();
        this.mContext = context;
        this.lamps = lamps;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext)
                .inflate(R.layout.item_lamp_unadded, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        final Category category = lamps.get(position);
        if (category.getType() == 1) {
            holder.titleText.setText(R.string.device_type_lawn);
        } else if (category.getType() == 2) {
            holder.titleText.setText(R.string.device_type_lawn_rgb);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mItemClickListener.onItemClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return lamps.size();
    }
}